class OrderController < ApplicationController
  before_filter :require_login
  include UsersHelper
  include OrderHelper
  include PaymentHelper
  
  def add_to_cart
    @product = Product.find(params[:id])
  end
  
  def save_to_cart
    add_item_to_order(params[:productid],params[:quantity],params[:comments])
    redirect_to :action => 'view_cart', :controller => 'order'
    return
  end

  def view_cart
    @order = get_current_order()
  end

  def confirm_order
    @order = get_current_order()
  end
  
  
  def remove_from_cart
    remove_item_from_order(params[:id])
    redirect_to :action => 'view_cart', :controller => 'order'
  end
  def edit_order_item
    @order_item = get_item_from_order(params[:id])
  end
  
  def edit_order_item_submit
    edit_item_from_order(params[:order_item_num],params[:quantity],params[:comments])
    redirect_to :action => 'view_cart', :controller => 'order'
    return
  end
  
  def checkout
    save_order()
    return
  end
  
  def init
    @product = Product.find(params[:productid])
    @user = userContext.user    
    @order_id = newOrderId
    userContext.add('orderId', @order_id)    
    userContext.add(@order_id, @product.id)
  end

  def submit
    @user = userContext.user
    s_token = params[:s_token]
    cc_masked = params[:cc_masked]
    order_id = params[:order_id]
    @res = process_order(userContext, order_id, s_token, cc_masked)                
  end
  
end
